	<!DOCTYPE html>
	<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>新疆车管家后台</title>
		<link rel="stylesheet" href="/Public/layui/css/layui.css">
		<style type="text/css">
		    body{margin: 10px;}
		    	.demo-carousel{height: 200px; line-height: 200px; text-align: center;
		    }
			#tree{
				width:300px; padding:20px;
			}
			#tree li i{
				color:#1E9FFF;
			}
		</style>
	</head>
	<body>
		 <blockquote class="layui-elem-quote">
			<div class="layui-inline">
				<label class="layui-form-label">搜索名称</label>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" placeholder="搜索名称/首字母" id="like">
				</div>
				<button class="layui-btn layui-input-inline" onclick="search()">搜索</button>
			</div>
		</blockquote>
		<fieldset class="layui-elem-fied site-demo-button">
			<legend>汽车品牌信息列表</legend>
			<table id="demo" lay-filter="demo"></table>
		</fieldset>

		<!-- 编辑商品表单 -->
	  <div id="editer" style="display:none; padding:20px;">
			<form class="layui-form">
				    <div class="layui-inline">
      					<label class="layui-form-label">搜索选择框</label>
	 					<div class="layui-input-inline">
		       				<select name="cartypeid" lay-verify="required" lay-search="">
		       					<option value="">直接选择</option>
		       					<volist name="cartype" id="vo">
		         						<option value="{$vo.id}">{$vo.name}</option>
		         				</volist>
		       				 </select>
		     			 </div>
		   			</div>
		   			<div class="layui-form-item" style="margin-top: 30px;">
						<div class="layui-input-block">
						  <button class="layui-btn" lay-submit lay-filter="insert">立即提交</button>
						  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
			</form>
		</div>
		
		<script src="/Public/layui/layui.all.js"></script>
		<script type="text/javascript">
			var head_ico_path = ""; //上传头像路径
			var car_id = 0; //选中用户ID
			var add_cars; //弹出窗口

			var like = "";
			var add_window;
			var id = 0;
			var object = {};
			var table = layui.table;
			table.render({
				elem: '#demo',
				url:"/Admin/Hotcar/get_hotcar_list",
				height: 500,
				width:1550,
				cellMinWidth:80,
				page:true,
				limit:10,
				loading:true,
				text: {    
					none: '暂无相关数据' //自定义文本，如空数据时的异常提示等默认：无数据。
				},
				cols: [[ //表头参数
					{field:'id', title:'ID', width: 80},
					{field:'car_type_id', width:100, title: '绑定的品牌'},
					{field:'logo', width:100, title: '热门品牌'},
					{field:'name', width:160, title: '热门名称'},
					{fixed: 'right', width:200, align:'center', toolbar: '#barDemo'} //设置表头的删改查
				]],
				response: {				//用于对返回的数据格式的自定义
					statusName:'code', //数据状态的字段名称，默认：code
					statusCode:200,	   //成功的状态码，默认：0
					msgName: 'msg', //状态信息的字段名称，默认：msg
					countName:'total', //数据总数的字段名称，默认：count
					dataName:'data'   //数据列表的字段名称，默认：data
				},
			});

			//方法级渲染表格重载 这里的表格重载是指对表格重新进行渲染，包括数据请求和基础参数的读取(多用于搜索)
			function search(){
				like = $('#like').val();
				//执行重载 重载默认执行当前控制器index方法
				table.reload('demo', {
					where: {  
						like: like  //设定异步数据接口的额外参数
					},
					page: {
						curr: 1 //重新从第 1 页开始
					}
			  });

			}

		//点击编辑按钮获取相关数据	
		 table.on('tool(demo)', function(obj){ 
			if (obj.event == "edit") {
				car_id=obj.data.id;
				add_car = layer.open({
					type: 1, 
					content: $('#editer'),
					area: ['400px', '400px;']
				});
			}

			if (obj.event == "del") {
				var index = layer.confirm('删除车型后无法恢复，确认删除?', {
					icon: 3, 
					title:'温馨提示'
				}, function(index){
					ajax('/Admin/Hotcar/del',{
						"id":obj.data.id
					},function(res){
						obj.del();  //删除对应行（tr）的DOM结构
						layer.close(index);
						layer.msg(res.msg);
					})
					
				});
			}
			console.log(obj);
		});

		//用户编辑保存
		form.on('submit(insert)', function(data){
			data.field.id=car_id;         
		    console.log(data.field);
		    var param=data.field;
		    ajax('/Admin/Hotcar/update',param,function(res){
				layer.close(add_car);
				layer.msg(res.msg);
				window.location.href="/Admin/Hotcar/index";
			})
			 return false; //阻止表单跳转
		});
		</script>
		<script type="text/html" id="barDemo">
			<div class="layui-btn-group">
				<button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="edit">编辑</button>
				<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</button>
			</div>
		</script>
	</body>
	</html>